package com.view
{
	import com.model.ModelLocator;
	
	import flash.events.AsyncErrorEvent;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import mx.containers.Canvas;
	import mx.controls.VideoDisplay;
	
	public class VideoPlayerClass extends Canvas
	{
		public var topBackTxt:TextField;
		public var bottomBackTxt:TextField;
		public var topTxt:TextField;
		public var topMaskImg:Canvas;
		public var bottomTxt:TextField;
		public var bottomMaskImg:Canvas;
		
		public var lyricCan:Canvas;
		
		public var video:VideoDisplay;	
		private var netConn:NetConnection;
		private var ns:NetStream;
		
		private var _model:ModelLocator;
		
		public function VideoPlayerClass()
		{
			super();
			_model = ModelLocator.getInstance();
		}
		
		protected function onAddToStage(event:Event):void
		{
			var format:TextFormat = new TextFormat("Impact", 30, _model.txtColor);
			format.align = TextFormatAlign.LEFT;
			topBackTxt = new TextField();
			topBackTxt.selectable = false;
			topBackTxt.width = 440;
			topBackTxt.height = 40;
			topBackTxt.x = 20;
			topBackTxt.y = 240;
			topBackTxt.defaultTextFormat = format;
			topBackTxt.text = "test.!!!@~~~~~~~~top....!!!@~~~~~~~~";
			
			this.rawChildren.addChild( topBackTxt );
			
			bottomBackTxt = new TextField();
			bottomBackTxt.selectable = false;
			bottomBackTxt.width = 440;
			bottomBackTxt.height = 40;
			bottomBackTxt.x = 20;
			bottomBackTxt.y = 280;
			bottomBackTxt.defaultTextFormat = format;
			bottomBackTxt.text = "bottom.-----test";
			this.rawChildren.addChild( bottomBackTxt );
			
			this.rawChildren.addChild( lyricCan );
			
			topTxt = new TextField();
			topTxt.selectable = false;
			topTxt.cacheAsBitmap = true;
			topTxt.width = 440;
			topTxt.height = 40;
			topTxt.x = 20;
			topTxt.defaultTextFormat = format;
			lyricCan.rawChildren.addChild( topTxt );
			topMaskImg.mask = topTxt;
			
			bottomTxt = new TextField();
			bottomTxt.selectable = false;
			bottomTxt.cacheAsBitmap = true;
			bottomTxt.width = 440;
			bottomTxt.height = 40;
			bottomTxt.x = 20;
			bottomTxt.y = 40;
			bottomTxt.defaultTextFormat = format;
			lyricCan.rawChildren.addChild( bottomTxt );
			bottomMaskImg.mask = bottomTxt;
			
		}
		
		public function init():void
		{
			addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
			
			
			
//			netConn = new NetConnection();
//			netConn.connect(null);
//			ns = new NetStream(netConn);
//			var clientobj:Object = new Object();
//			clientobj.onMetaData = function():void{};
//			ns.client = clientobj;
//			ns.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
//			ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onASYNCError);
//			ns.play("assets/青花瓷.flv");
//			var v:Video = new Video();
//			v.attachNetStream(ns);
//			rawChildren.addChild( v );
		}
		
		protected function onASYNCError(event:AsyncErrorEvent):void
		{
			trace("async error");
		}
		
		protected function onIOError(event:IOErrorEvent):void
		{
			trace("io error");
		}
		
		public function stop():void
		{
//			ns.pause();
//			ns.close();
			topBackTxt.text = topTxt.text = bottomBackTxt.text = bottomTxt.text = ""; 
			topMaskImg.width = bottomMaskImg.width = 0;
		}
		
		
	}
}